package org.lightrpc.server;

import java.util.HashMap;
/**
 * This class stores all the names of the services that are registered. 
 * Currently implemented as a "static" class, could be a singleton/factory approach?
 * @author miku
 *
 */
public class WebServiceRegistry {

	private static HashMap<String, Object> registry;
	
	static{
		registry = new HashMap<String, Object>();
	}
	/**
	 * Registers a single webservice.
	 * @param clazz
	 * @param object
	 */
	//FIXME: It's probably not this classes responsibility to find out the names used to register the service?
	protected static void registerService(Class<?> clazz, Object object){
		//register with the simple name and all of it's interfaces names, so clients can use them to call it
		registry.put(clazz.getSimpleName().toLowerCase(), object);
		Class<?>[] faces = clazz.getInterfaces();
		for (Class<?> iface : faces) {
			registry.put(iface.getSimpleName().toLowerCase(), object);
		}
	}
	
	public static Object findService(String name){
		return registry.get(name.toLowerCase());
	}
}
